package cn.com.dashihui.web.controller;


import java.util.ArrayList;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresAuthentication;

import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.Record;

import cn.com.dashihui.kit.ExcelExportUtil.Pair;
import cn.com.dashihui.web.base.BaseController;
import cn.com.dashihui.web.service.AuthDownloadService;

@RequiresAuthentication
public class AuthDownloadController extends BaseController{
	private AuthDownloadService downloadService=new AuthDownloadService();
	
	public void index(){	    	
	   render("index.jsp");
	}
	 
	public void page(){
		System.out.println("进来了");
		int pageNum = getParaToInt(0, 1);
		int pageSize = getParaToInt("pageSize", PropKit.getInt("constants.pageSize"));
		renderResult(0,downloadService.findPage(pageNum, pageSize));
	}
	
	/**
	 * excel导出
	 */
	public void doExcel(){
		List<Pair> titles = new ArrayList<Pair>();
	    titles.add(new Pair("logName", "登陆平台"));
	    titles.add(new Pair("name", "登陆人"));
	    titles.add(new Pair("accountRole", "账号角色"));
	    titles.add(new Pair("storeName", "所属分公司"));
	    titles.add(new Pair("downloadDate", "下单时间"));
	    titles.add(new Pair("memberDownload", "会员信息下载"));
	    titles.add(new Pair("orderDownload", "订单统计下载"));
	    titles.add(new Pair("offlineDownload", "线下统计下载"));
	    titles.add(new Pair("integralDownload", "会员下载"));
	    titles.add(new Pair("arrivedDownload", "抵现明细下载"));
	    
		List<Record> list=downloadService.findPageExcel();
		List<Record> listz=new ArrayList<Record>();
		for (int i = 0; i < list.size(); i++) {
			Record record=new Record();
				record.set("logName",list.get(i).get("logName"));
				record.set("name", list.get(i).get("name"));
				record.set("accountRole", list.get(i).get("accountRole"));
				record.set("storeName", list.get(i).get("storeName"));
				record.set("store", list.get(i).get("store"));
				record.set("downloadDate", list.get(i).get("downloadDate"));
		
			if( list.get(i).get("memberDownload").equals(0)){
				record.set("memberDownload", "否");
			}else{
				record.set("memberDownload", "是");
			}
			if( list.get(i).get("orderDownload").equals(0)){
				record.set("orderDownload", "否");
			}else{
				record.set("orderDownload", "是");
			}
			
			
			if( list.get(i).get("offlineDownload").equals(0)){
				record.set("offlineDownload", "否");
			}else{
				record.set("offlineDownload", "是");
			}
			

			if( list.get(i).get("integralDownload").equals(0)){
				record.set("integralDownload", "否");
			}else{
				record.set("integralDownload", "是");
			}
			
			if( list.get(i).get("arrivedDownload").equals(0)){
				record.set("arrivedDownload", "否");
			}else{
				record.set("arrivedDownload", "是");
			}
	
			listz.add(record);
 		}
		// 导出
		downloadService.exportVip(getResponse(), getRequest(),titles, listz);		
		renderNull();
	}
}
